// 过滤路由表
const calcPermissions = (actual, routes, ret = []) => {
  // actual:后台返回的权限路由  routes：页面初始化的路由

  actual.forEach((item, index) => {
    const h5Uri = item.h5Uri
    const child = routes.find(i => (i.path === h5Uri || i.path === '/' + h5Uri))
    let arr = []
    let hiddenArray = []
    // 一级菜单
    if (child) {
      const idx = ret.findIndex(k => k.path == child.path)
      if (idx < 0) {
        child.meta.title = item.name;
      }

      // 二级菜单
      (child.children || []).forEach(k => {
        let o = (item.childList).findIndex(j => {
          let mmm = j.h5Uri == k.path || ('/' + j.h5Uri) == k.path
          return mmm;
        })
        
        if (o >= 0) {
          k.meta.name = item.childList[o].name;
          k.meta.title = item.childList[o].name;
          arr[o] = k;
        } else {
          // 隐藏菜单 丢进路由里面
          if (k.meta.edit || k.hidden) {
            hiddenArray.push(k)
          }
        }
      })
      //ret[index] = { ...child, children: arr.concat(hiddenArray) };
      let _children = arr.concat(hiddenArray) 
      let nnn = _children.filter(j => j )
      ret.push({ ...child, children: nnn })
    }
  })
  console.log(ret)
  return ret
}

export { calcPermissions }
